<?php
	class CategoryAction extends CommonAction{
		function _filter(&$map){
			$map['c_name'] = array('like',"%".$_POST['searchname']."%");
		}	
		public function _before_add(){
			$category = D('Category');
			$categorylist = $category -> field('c_id,c_name') -> findAll();
			$this -> assign("categorylist",$categorylist);
		}
		
		public function _before_edit(){
			$category = D('Category');
			$categorylist = $category -> field('c_id,c_name') -> findAll();
			$this -> assign("categorylist",$categorylist);			
		}
		
		public function insert(){
			$Category = D("Category");
			if(!$Category -> create()){
				$this -> error($Category -> getError());	
			}else{
				$Category->c_createtime = date("Y-m-d H:i:s",time());
				if($Category -> add()){
					$this -> success("类别添加成功");	
				}else{
					$this -> error("无法添加类别");
				}
			}
		}
		
		// 检查帐号
		public function checkAccount() {

	    }

	    /**
	     * 禁用状态(重载父类方法)
	     * @see temiweb/Lib/Action/CommonAction#forbid()
	     */
		public function forbid() {
			$name=$this->getActionName();
			$model = D ($name);
			$pk = $model->getPk ();
			$id = $_REQUEST ['id'];
			$condition = array ($pk => array ('in', $id ) );
			$list=$model->forbid ( $condition,'c_status' );
			if ($list!==false) {
				$this->assign ( "jumpUrl", $this->getReturnUrl () );
				$this->success ( '状态禁用成功' );
			} else {
				$this->error  (  '状态禁用失败！' );
			}
		}

		/**
	     +----------------------------------------------------------
		 * 默认恢复操作,重裁父类方法
		 *
	     +----------------------------------------------------------
		 * @access public
	     +----------------------------------------------------------
		 * @return string
	     +----------------------------------------------------------
		 * @throws FcsException
	     +----------------------------------------------------------
		 */
		function resume() {
			//恢复指定记录
			$name=$this->getActionName();
			$model = D ($name);
			$pk = $model->getPk ();
			$id = $_GET ['id'];
			$condition = array ($pk => array ('in', $id ) );
			if (false !== $model->resume ( $condition,'c_status' )) {
				$this->assign ( "jumpUrl", $this->getReturnUrl () );
				$this->success ( '状态恢复成功！' );
			} else {
				$this->error ( '状态恢复失败！' );
			}
		}
		
		/**
		 * 获取父类名称
		 * @return unknown_type
		 */
		function getParentCategory(){
			$categoryObj = M("Category");
			$categoryList = $categoryObj -> where("c_status=1") -> findAll();
			if(is_array($categoryList) && !empty($categoryList)){
				foreach($categoryList as $k=>$v){
					$categoryList[$k]['backstr'] = "{id:'".$v['c_id']."',orgName:'".$v['c_name']."'}";
				}
			}
			$this -> assign("categoryList",$categoryList);
			$this -> display();
		}
	}
?>